package com.mt.api.modules.controller;

import com.mt.common.response.WebResponse;
import com.mt.common.response.WebResponseUtils;
import com.mt.log.annotation.Log;
import com.mt.api.modules.domain.bo.AppOrderAddBo;
import com.mt.api.modules.domain.bo.AppOrderFinishBo;
import com.mt.api.modules.service.AppOrderBackService;
import com.mt.api.util.ParamsValid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author plover
 * @date 2020-07-06
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "order管理")
@RequestMapping("/app/order/back")
public class AppOrderBackController {

    private final AppOrderBackService orderBackService;

    @PostMapping("/add")
    @Log("销售退回单")
    @ApiOperation(value = "", notes = "销售退回单接口", httpMethod = "POST")
    public WebResponse backOrderAdd(@RequestBody AppOrderAddBo resources) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("客户不能为空", resources.getCustomerId());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return orderBackService.backOrderAdd(resources);
    }

    @PostMapping("/cancel")
    @Log("销售单撤销")
    @ApiOperation(value = "", notes = "销售单撤销接口", httpMethod = "POST")
    public WebResponse cancelBackOrder(@RequestBody AppOrderFinishBo resources) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("销售单不存在", resources.getId());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return orderBackService.cancelBackOrder(resources);
    }

}